const punch = (data, state, running, site, err) => {
  // console.log("数组==>", running);
  if (running.length > 20) {
    running = running.slice(0, 15);
  }

  running.unshift(site + Number(data.valu[4].v));

  //  冲床启动和停止
  if (data.valu[5].v == 1) {
    state.isStart = false;
    state.img = require("../../assets/images/machine01.png");
  }
  if (data.valu[6].v == 1) {
    state.isStart = true;
  }
  if (state.isStart == true) {
    if (data.valu[1].v == 1) {
      state.isactive = false;
      state.hint.error = `${state.name}正常运行`;
      state.img = require("../../assets/images/machine01-run.gif");
    }
    // 冲床正常和异常
    if (data.valu[0].v == 1) {
      state.isactive = true;
      state.hint.error = `${state.name}请派人进行检查或维修`;
      state.img = require("../../assets/images/machine01-fault.gif");
      err.unshift({
        name: state.name,
        t: new Date(),
      });
    }
    // 冲床换模
    if (data.valu[2].v == 1) {
      state.hint.maintain = `${state.name}换模完成`;
    }
    if (data.valu[3].v == 1) {
      state.hint.maintain = `${state.name}换模中`;
    }

    if (data.valu[4].v == 1) {
      state.hint.maintain = `${state.name}自动冲压完成`;
    }

    // 警报灯
    if (data.valu[7].v == 1) {
      state.isAlarm = true;
    } else {
      state.isAlarm = false;
    }
    // 冲床使用模具
    if (data.valu[8].v == 1) {
      return (state.hint.instruct = `${state.name}使用1号模具`);
    }

    if (data.valu[9].v == 1) {
      return (state.hint.instruct = `${state.name}使用2号模具`);
    }

    if (data.valu[10].v == 1) {
      return (state.hint.instruct = `${state.name}使用3号模具`);
    }

    if (data.valu[11].v == 1) {
      return (state.hint.instruct = `${state.name}使用4号模具`);
    }

    if (data.valu[12].v == 1) {
      return (state.hint.instruct = `${state.name}使用5号模具`);
    }
  }
};

module.exports = {
  punch,
};
